//
//  SEProfileViewModel.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/27.
//

import UIKit

class SEProfileViewModel: SEBaseViewModel {
    var patientListViewModel = SEPatientListViewModel(withLoading: false)

    var isLogin: Bool {
        return !UserDefaults.authToken.isEmpty
    }

    var userNick: String {
        return isLogin ? UserDefaults.userNick : "登录/注册"
    }

    var avatorImg: String {
        return UserDefaults.userAvatar
    }

    var selectedPatientViewModel = SEPatientDetailViewModel()

    var patientList: [SEPatientDetailModel] {
        var ary: [SEPatientDetailModel] = []
        ary.append(contentsOf: patientListViewModel.models)
        ary.append(SEPatientDetailModel())
        return ary
    }

    func patientViewModel(indexPath: IndexPath) -> SEPatientDetailViewModel {
        return SEPatientDetailViewModel(model: patientList[indexPath.item])
    }

    var numberOfItemsForPatientCollectionView: Int {
        return isLogin ? patientList.count : 1
    }

    var colletionViewCellType: [SEProfileRecordCvCellType] {
        if isLogin {
            var ary = [SEProfileRecordCvCellType]()
            for i in 0..<numberOfItemsForPatientCollectionView {
                if i == numberOfItemsForPatientCollectionView - 1 {
                    ary.append(.add)
                } else {
                    ary.append(.info)
                }
            }
            return ary
        } else {
           return  [.login]
        }
    }

    func requestPatientList() {
        patientListViewModel.requestPatientList()
        patientListViewModel.updateData = { status in
            self.updateData?(status)
        }
    }
}
